<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of MlsController
 *
 * @author Poh Nean
 */
class ProjectsController extends PsController
{

	public $layout = 'manage';

	public function accessRules()
	{
		return CMap::mergeArray(array(
					array('allow',
						'roles' => array('ManageModule.Projects'),
					),
						), parent::accessRules());
	}

	public function actionIndex()
	{
		$agency = $this->loadAgency();

		if ($agency->settings == null) {
			$agency->settings = array();
		}

		if (!empty($_POST['AgencySetting'])) {
			foreach ($_POST['AgencySetting'] as $key => $value) {
				$agency->setSetting($key, $value);
			}

			if ($agency->save(true, array('settings'))) {
				PsSystemMessage::add('Your changes have been saved.', 'success');
				$this->refresh();
			}
		}

		$data = array();
		$data['agency'] = $agency;
		$this->render('index', $data);
	}

	public function actionAttrSetting()
	{
		$propject_exception_list = array('id', 'agency_id', 'cover_photo_url', 'cover_photo_user_file_id', 'country_code', 'property_id', 'deleted');

		$project = new Project;
		$mlsListing = new MlsListing;

		$data = array();
		$data['module'] = $this->module->name;
		$data['controller'] = $this->getUniqueId();
		$data['project'] = $project;
		$data['mlsListing'] = $mlsListing;
		$data['propject_exception_list'] = $propject_exception_list;
		$this->render('attrsetting', $data);
	}

	public function loadAgency()
	{
		return Yii::app()->user->model->agency;
	}

}

?>
